<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link href="<%=basePath %>bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
    <script src="<%=basePath %>bootstrap/js/jquery.min.js"></script>
    <script src="<%=basePath %>bootstrap/js/bootstrap.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
    <script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>
</head>
<body>

<div class="col-md-4" >
    <div id="toolbar" class="btn-group">
        <button id="btn_save" type="button" class="btn btn-default ">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>保存
        </button>
    </div>
    <table id="reportTable" ></table>
</div>
<div class="col-md-8" id="grouplist">
</div>
</body>
<script type="text/javascript">
    $(function () {
        var tableconfig = {
            method: 'get',
            toolbar: '#toolbar',
            cache: false,
            height: 650,
            striped: true,
            pagination: false,
            sidePagination: 'client',
            search: true,
            showColumns: false,
            showRefresh: false,
            showExport: false,
            clickToSelect: true,
            singleSelect : true,
            columns:
                [
                    {
                        checkbox: true
                    },
                    {field: "code", title: "科室代码", align: "center", valign: "middle"},
                    {field: "name", title: "科室名称", align: "center", valign: "middle"}
                ],
            url: getRootPath_web() + '/dept/selectAllDept',
            onClickRow:function(row, $element,field){
                console.log(row.code);
            }
        }

        $('#reportTable').bootstrapTable(tableconfig);
        $.get(getRootPath_web()+"/deptGroup/selectDeptAndGeptGroup",{},function (data) {
            $(data).each(function () {
                $("#grouplist").append("<label >"+this.groupname+"</label>");
                $("#grouplist").append("<div>");
                $(this.items).each(function(){
                        $("#grouplist").append("<label class=\"checkbox-inline\">\n" +
                            "            <input type=\"checkbox\" id=\"inlineCheckbox1\" value=\""+this.code+"\"> "+this.name+"\n" +
                            "        </label>\n" )
                    }
                )
                $("#grouplist").append("</div><br>");

            });
        },'json')

        $('#btn_save').click(function () {
            var evalDeptIdStr = ",";
            $("#grouplist input:checked").each(function () {
                evalDeptIdStr += $(this).attr("value");
                evalDeptIdStr += ","

            })
            $.post(getRootPath_web()+"/deptMapper/addDeptMapper",{
                deptId:$('#reportTable').bootstrapTable('getSelections')[0].code,
                evalDeptId:evalDeptIdStr
            },function (data) {
                if (data){
                    bootbox.alert("添加成功");
                } else{
                    bootbox.alert("添加失败");
                }
            },'json')
        });

    });

</script>
</html>